/*
 * @Description: 报表api
 * @Author: Zzt
 * @Date: 2022-11-09 11:35:08
 * @LastEditTime: 2023-03-04 15:16:14
 */

import { reportRequest } from '@/utils/request';
import type { Key } from 'react';
import type { IPageQuery, ICoordinate } from '@/interfaces/global';

/**
 * 暂时放这，后期改成通用地址
 */
// 报表设计链接
export const downloadBaseurl = 'http://192.168.0.202:8079/report/report/download/pdf';
// 报表预览链接
export const previewMutiBaseurl = 'http://192.168.0.202:8079/report/report/mulPreview';
// 报表设计链接
export const designBaseurl = 'http://192.168.0.202:8079/report/';
// 报表预览链接
export const previewBaseurl = 'http://192.168.0.202:8079/report/report/jp/preview/';
// END

// 增加报表模板
export interface IAddReportTempParams extends ICoordinate {
  name: string;
  type: number;
  remark: string;
}
export function addReportTemp(data: IAddReportTempParams) {
  return reportRequest({
    url: `/templateGroup/save`,
    method: 'post',
    data
  });
}

// 编辑报表模板
export interface IEditReportTempParams extends IAddReportTempParams {
  id: number;
}
export function editReportTemp(data: IEditReportTempParams) {
  return reportRequest({
    url: `/templateGroup/update`,
    method: 'put',
    data
  });
}

interface fetchReportTempListProps extends Partial<ICoordinate> {
  name?: string;
  order?: string;
  orderField?: string;
}
// 分页查询报表条目
export function fetchReportList(data: fetchReportTempListProps) {
  return reportRequest({
    url: `/templateGroup/list`,
    method: 'post',
    data
  });
}

// 分页查询报表条目
export function fetchReportListByPage(data: IPageQuery<fetchReportTempListProps>) {
  return reportRequest({
    url: `/templateGroup/page`,
    method: 'post',
    data
  });
}

// 通过id删除报表
export function deleteReportList(ids: Key) {
  return reportRequest({
    url: `/templateGroup/delete/${ids}`,
    method: 'delete'
  });
}

/* 直接打印 */
export function reportPrint() {
  return reportRequest({
    url: `/templateGroup/report/print/`,
    method: 'get'
  });
}

/* 报表预览 */
export function reportPreview(id: Key, data?: any) {
  return reportRequest({
    url: `report/jp/preview/${id}`,
    method: 'post',
    data,
    responseType: 'arraybuffer'
  });
}

/* 报表预览 */
export function reportMutiPreviewUrl(params: any) {
  return reportRequest.getUri({
    url: `report/mulPreview`,
    method: 'get',
    params
  });
}
